<template>
  <div class="app-container">
    <!-- 若依经典布局 -->
    <el-table :data="tableData" v-loading="loading">
      <el-table-column prop="name" label="姓名" />
      <el-table-column prop="age" label="年龄" />
      <el-table-column prop="no" label="学号" />
    </el-table>
  </div>
</template>

<script>
import { listStudents } from "@/api/amyproject"
export default {
  methods: {
    getList() {
      this.loading = true;
      listStudents().then(response => {
        this.tableData = response.rows;
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    }
  },
  created() {
    this.getList(); // 组件创建时自动召唤数据
  },
  methods: {
  handleImport({ file }) {
    const formData = new FormData()
    formData.append('file', file)
    importStudent(formData).then(res => {
      this.$message.success(res.msg)
      this.getList() // 刷新表格
    })
  },
  beforeUpload(file) {
    const isExcel = file.type.includes('sheet')
    if (!isExcel) {
      this.$message.error('只能上传Excel文件哦▼・⌒・▼')
    }
    return isExcel
  }
}
}
</script>
<style>

</style>